package vtt.android.dapanhc.dialogs;

import vtt.android.dapanhc.R;
import android.R.anim;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TextView;

public class DialogManager {

	private Context mContext;
	private IDialogListener mDialogListener;

	public DialogManager(Context ctx) {
		this.mContext = ctx;
	}

	public void addDialogListener(IDialogListener listener) {
		mDialogListener = listener;
	}

	public void showAlertDialog(final String dlName, String title, String message, boolean hasCancelButton) {
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		// set title
		if(!"".equals(title)){
			//dialog.setTitle(title);
		}
		// set dialog message
		dialog.setMessage(message);
		dialog.setCancelable(false);
		dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.cancel();
				if (mDialogListener != null) {
					mDialogListener.onOkClick(dlName);
				}
			}
		});
		// check whether display cancel button
		if (hasCancelButton) {
			dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.cancel();
					if (mDialogListener != null) {
						mDialogListener.onCancelClick(dlName);
					}
				}
			});
		}

		// create alert dialog
		AlertDialog alertDialog = dialog.create();
		// show it
		alertDialog.show();
	}
	
	public void showScoreResultDialog(final String dlName, String cSentence, String cPoint, String finishTime, String ponus, String total) {
		
		final Dialog dialog = new Dialog(mContext, R.style.theme_dialog_custom);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.dialog_score_result);
		
		((TextView) dialog.findViewById(R.id.correct_score)).setText(cSentence);
		((TextView) dialog.findViewById(R.id.correct_point)).setText(cPoint);
		((TextView) dialog.findViewById(R.id.time_finish)).setText(finishTime);
		((TextView) dialog.findViewById(R.id.time_ponus)).setText(ponus);
		((TextView) dialog.findViewById(R.id.total_point)).setText(total);
		
		dialog.findViewById(R.id.btn_close).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.cancel();
				mDialogListener.onCancelClick(dlName);
			}
		});
		
		dialog.findViewById(R.id.btn_leader_board).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.cancel();
				mDialogListener.onViewLeaderBoardClick(dlName);
			}
		});
		
		dialog.setCancelable(false);
		dialog.show();
	}

	public interface IDialogListener {
		public void onOkClick(String dialogName);

		public void onCancelClick(String dialogName);
		
		public void onViewLeaderBoardClick(String dialogName);
	}

}
